package logic

import (
	"context"
	"person/personrpc/personrpc"

	"person/api/internal/svc"
	"person/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdatePerfectLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdatePerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePerfectLogic {
	return &UpdatePerfectLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdatePerfectLogic) UpdatePerfect(req *types.UpdatePerfectRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	perfect, err := l.svcCtx.PersonRpc.UpdatePerfect(l.ctx, &personrpc.UpdatePerfectRequest{
		UserId:  req.UserId,
		Age:     req.Age,
		Email:   req.Email,
		Address: req.Address,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Date:    nil,
		}, nil
	}

	return &types.Response{
		Message: "完善信息成功",
		Code:    200,
		Date:    perfect,
	}, nil
}
